In this demo, you will
learn how to install and use the Material
library in your React app. Open the official website of
the latest Material library. Material is a UI library with
predefined and freestyle, basic and advanced components. You can use Material
by importing it into your React app file. Based on requirements,
Material can be customized. There are several
components defined on the official
website of Material. All the components can
be used in your app just by installing the
React Material Package. Now, open the installation
guide of the Material library. You can see that
there are two ways to install Material in your app, which are using NPM
script and using Yarn. Copy the NPM script to
install Material in your app. Create a React app using
the NPX create React app. Now to install Material
in the application, open the app.js file
provided by NPX. Open the terminal
from root folder of your app and paste the
copied NPM script. Click "Enter" to start
the installation of all Materials packages and
the peer dependencies. To verify the installation, open the package.json file. You can observe that
three new packages got added to your
dependency object. They are MUI Material, MUI emotion react, and MUI emotions style. Now you will learn how
the Material can be used in the app.js file. First of all, remove all
the extra code provided by the NPX create React app
under the header section. Now save the file. Open the app.css file and comment on the background
color code of your app. Open the app.js file again. Create a new div under the header where you will
use the Material component. Choose a Material button
component that you are going to import
and using your app. To use the Material button, you must import the
button component from the MUI Material Package and declare the
button component. Accepts prompts such as color, size, and label. Choose primary as
the button color, select large as the button size, and click the Material
button as the label. Now, save the file and check
the output of this code. In UI, you can observe a default Material button large in size with the primary color. Now, go to the Material
component guide of the button. Open the docs tab
on the website. Open the button component
in the component section. Here you can see different types of
features for the button, such as texts contained, outlined, disabled,
or link type. Alternatively, you can
add a disabled elevation. There are several
more options you can provide to your
button component. Go back to the code and
add another prop variant. Write variant as contained, save the file and
execute the code. Observe the output in UI, the elevated button is contained and is filled
with primary color. Now, install Material
icons in your React app. To install Material
icons in your React app, you have to install a
package called MUI icons Material using NPM
or using Yarn. Copy the NPM script and paste the script
into the terminal. Click "Enter" to
install the package. To verify the installation,
open package.json. Here, you can see a new
package MUI icons Material. Now import the icon
button from MUI Material, which wraps some icons into it and renders the
icons as a button. Then import the
photo camera icon from the Material
UI icons Package. In the div tag, write the
icon button component, and pass the photo camera
icon as a children element. Set the photo camera icons, font size as large, save the file and execute
it to see the output. In the UI window, you can see a photo
camera icon is displayed. The photo camera icon is the default Material icon
with no color to it. Now, add some color to
the photo camera icon. Color can be added
to the icon button using color props that accepts values such as success,
primary, and secondary. Choose success as the value. Save the file and execute. Here, you can observe the
color change of the icon. This way, you can use icons
in your app. Thank you.